#ifndef D_HELPER_MATH_H
#define D_HELPER_MATH_H

#include <math.h>
#include <time.h>
#include <stdlib.h>

#define PI 3.141592f
#define PI_OVER_360 0.008726649f

namespace DelGE
{
	namespace Helpers
	{
		namespace Math
		{
			class MathHelper
			{
			public:
				static int NextPowerOf2(int iNumber);
				static bool IsPowerOf2(int iNumber);

				static float DegreesToRadians(float fDegrees);
				static float RadiansToDegrees(float fRadians);

				static void SeedRandom(int iSeed = -1);
				static int Random(int iMax);
			};

			inline int MathHelper::NextPowerOf2(int iNumber)
			{
				// Based from http://acius2.blogspot.com/2007/11/calculating-next-power-of-2.html
				if (MathHelper::IsPowerOf2(iNumber))
					return iNumber;

				iNumber--;
				iNumber = (iNumber >> 1) | iNumber;		// 2 bit
				iNumber = (iNumber >> 2) | iNumber;		// 4 bit
				iNumber = (iNumber >> 4) | iNumber;		// 8 bit
				iNumber = (iNumber >> 8) | iNumber;		// 16 bit
				iNumber = (iNumber >> 16) | iNumber;	// 32 bit
				iNumber++;

				return iNumber;
			}

			inline bool MathHelper::IsPowerOf2(int iNumber)
			{
				return (iNumber & (iNumber - 1)) == 0;
			}

			inline float MathHelper::DegreesToRadians(float fDegrees)
			{
				return fDegrees * (PI / 180.0f);
			}
			
			inline float MathHelper::RadiansToDegrees(float fRadians)
			{
				return fRadians * (180.0f / PI);
			}
		}
	}
}

#endif